package com.demoo.zjsu.util.ExceptionToString;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * Created by jshjsh on 2016/8/14.
 * 将异常堆栈转换成字符串
 */
public class ExceptionLog {

    private static StringWriter stringWriter;
    private static PrintWriter printWriter;

    public static String toString(Exception Ex){
         stringWriter = new StringWriter();
         printWriter = new PrintWriter(stringWriter, true);
        Ex.printStackTrace(printWriter);
        printWriter.flush();
        stringWriter.flush();
        return stringWriter.toString();
    }

    public static void destory() {
        if (printWriter != null)
            printWriter.close();
        if (stringWriter != null) {
            try {
                stringWriter.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}
